package com.service.scheduler.sched;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerKey;

import com.service.cache.CacheManager;
import com.service.other.Logger;
import com.service.scheduler.server.SchedulerCreator;
import com.service.scheduler.job.BaiduApiGeoconvJob;
import com.service.scheduler.job.BaiduApiTelematicsJob;


public class BaiduApiSched {
	
	private Scheduler sched;
	
	public void init(){
			try {
				sched = SchedulerCreator.createScheduler(BaiduApiSched.class.getSimpleName(),1,5);
				this.initBaiduApiTelematics();
//				this.initBaiduApiGeoconv();
				CacheManager.instance().schedMap.put(sched.getSchedulerName(),sched);
			} catch (SchedulerException e) {
				Logger.err(e);
			}
			
	}
	
	public void initBaiduApiTelematics() throws SchedulerException{
		JobKey jobKey = SchedulerCreator.createJobKey("telematics", "com.service.api");
		TriggerKey triggerKey = SchedulerCreator.createTriggerKey("telematics","com.service.api");
		String cronExpr = SchedulerCreator.createMinuteExpr(10);
		JobDetail job = SchedulerCreator.createJob(jobKey, BaiduApiTelematicsJob.class);
		//job.getJobDataMap().put("GpsNo", bean.GpsNo);
		CronTrigger cronTrigger = SchedulerCreator.createCronTrigger(triggerKey,cronExpr);
		sched.scheduleJob(job, cronTrigger);
	}
	
	public void initBaiduApiGeoconv() throws SchedulerException{
		JobKey jobKey = SchedulerCreator.createJobKey("geoconv", "com.service.api");
		TriggerKey triggerKey = SchedulerCreator.createTriggerKey("geoconv","com.service.api");
		String cronExpr = SchedulerCreator.createSecondExpr(20);
		JobDetail job = SchedulerCreator.createJob(jobKey, BaiduApiGeoconvJob.class);
		CronTrigger cronTrigger = SchedulerCreator.createCronTrigger(triggerKey,cronExpr);
		sched.scheduleJob(job, cronTrigger);
	}
	
}
